package cn.yfj.basic.service.impl;

import cn.yfj.basic.mapper.BaseMapper;
import cn.yfj.basic.query.BaseQuery;
import cn.yfj.basic.service.IBaseService;
import cn.yfj.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)//事务的管理默认不提交
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> tMapper;

    @Transactional //(readOnly = false,propagation = Propagation.REQUIRED)
    @Override
    public void save(T t) {
        tMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        tMapper.update(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        tMapper.delete(id);
    }

    @Override
    public T queryById(Long id) {
        return (T)tMapper.loadById(id);
    }

    @Override
    public List<T> queryAll() {
        return tMapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        //查询总条数
        Long total = tMapper.count(query);
        // 查询当前页的数据
        List<T> rows = tMapper.queryData(query);
        return new PageList<>(total,rows);
    }

    @Override
    public void conndel(Long types_id) {
        tMapper.conndel(types_id);
    }

    @Override
    @Transactional
    public void bach(List<Long> ids) {
        tMapper.bach(ids);
    }

}
